package com.lz.service.smsmail.exception;

import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.google.gson.Gson;
import com.lz.service.common.response.CommonServiceResponseEnum;
import com.lz.service.common.response.ResponseBody;
import com.lz.service.smsmail.common.Constants;
import com.lz.service.smsmail.common.RequestContext;

/**
 * 全局异常处理
 * @author likejian
 *
 */
@ControllerAdvice(basePackages={Constants.CONTEN_TTYPE_JSON})
public class GlobalExceptionHandler {
	
	private static Gson GSON = new Gson();
	
    @ExceptionHandler(RuntimeException.class)
    @org.springframework.web.bind.annotation.ResponseBody  
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseBody exceptionHandler(RuntimeException e, HttpServletResponse response) {
    	ResponseBody resp = new ResponseBody(CommonServiceResponseEnum.IS_ERROR);
    	RequestContext.exceptionLog(e);
    	RequestContext.end(GSON.toJson(resp));
        return resp;
    }
}